package com.youlai.boot.system.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.system.model.dto.AuditRequestDTO;
import com.youlai.boot.system.model.entity.RequestWaste;
import com.youlai.boot.system.model.entity.WasteType;
import com.youlai.boot.system.model.vo.CalculatePriceVO;
import com.youlai.boot.system.model.vo.TaskAssignmentVO;
import com.youlai.boot.system.service.TaskAssignmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 张雨润
 * @date 2025/2/26 15:56
 * @Description 配送任务
 */
@RestController
@RequestMapping("/api/v1/tasks")
@RequiredArgsConstructor
public class TaskAssignmentController {
    private final TaskAssignmentService taskAssignmentService;

    /**
     * 查询配送员任务列表
     * @param courierId
     * @return
     */
    @GetMapping("/courier/list")
    public Result<List<TaskAssignmentVO>> getCourierTaskList(@RequestParam("courierId") Long courierId) {
        List<TaskAssignmentVO> taskAssignmentVOList = taskAssignmentService.getCourierTaskList(courierId);
        return Result.success(taskAssignmentVOList);
    }

    /**
     * 查询配送员指定任务
     * @param taskId
     * @return
     */
    @GetMapping("/courier/{taskId}")
    public Result<TaskAssignmentVO> getCourierTask(@PathVariable("taskId") Long taskId) {
        TaskAssignmentVO taskAssignmentVO= taskAssignmentService.getCourierTask(taskId);
        return Result.success(taskAssignmentVO);
    }


    /**
     * 一键计算收益
     * @param wasteList
     * @return
     */
    @PostMapping("/calculate")
    public Result<CalculatePriceVO> calculatePrice(@RequestBody List<RequestWaste> wasteList){
        CalculatePriceVO vo = taskAssignmentService.calculatePrice(wasteList);
        return Result.success(vo);
    }


    /**
     * 配送人确认回收垃圾
     * @param dto
     * @return
     */
    @PostMapping("/courier/audit")
    public Result<Boolean> auditAssignTask(@RequestBody AuditRequestDTO dto) {
        Boolean rs =  taskAssignmentService.auditAssignTask(dto);
        return Result.success(rs);
    }
}
